<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>注册</title>
    <link rel="stylesheet" href="/admin/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/admin/css/login.css"/>
    <script type="text/javascript" src="/admin/plugins/layui/layui.js"></script>
    <link rel="stylesheet" href="/admin/js/validator/validator.css"/>
    <script type="text/javascript" src="/admin/js/validator/validator.js"></script>
</head>

<body class="beg-login-bg">
<div class="beg-login-box">
    <header>
        <h1>注册用户</h1>
    </header>
    <div class="beg-login-main">
        <form action="/admin/reg" class="layui-form" method="post" id="validate">
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe612;</i>
                </label>
                <input type="text" name="username" id="username" is-yz="true" yz-type="null,phone" lay-verify="userName" autocomplete="off" placeholder="请输入手机号"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe642;</i>
                </label>
                <input type="password" name="password" id="password" is-yz="true" yz-type="null,password" eq-id='password_required' lay-verify="password" autocomplete="off" placeholder="请输入密码"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe642;</i>
                </label>
                <input type="password" name="password" id="password_required" is-yz="true" yz-type="null,password" eq-id='password' lay-verify="password" autocomplete="off" placeholder="请再次输入密码"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="beg-pull-right">
                    <button class="layui-btn layui-btn-primary" lay-submit lay-filter="reg">
                        <i class="layui-icon">&#xe650;</i> 注册
                    </button>
                </div>
                <div class="beg-clear"></div>
            </div>
        </form>
    </div>
</div>

<script>

    var validate = $("#validate").validator();

    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form();

        form.on('submit(reg)', function (data) {

            if(!validate.check()){
                return;
            }

            $.ajax({
                url: "/admin/reg",
                type: "post",
                dataType: "json",
                data: {"id":id},
                success: function (r) {
                    console.log(r);

                    if(r.code == -1){
                        layer.msg(r.msg);
                        return;
                    }
                    layer.close(index);
                    layer.msg('修改成功!',{time:1500}, function(){
                        location.reload();
                    });
                }
            });

        });
    });
</script>
</body>

</html>